-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added support to customizable the projectFileExtensions
.
#19550
Added support to customizable the projectFileExtensions
.
#19550
Conversation
TC Format Checker Report - 03:56 - 18 - JunThere are 2 files with format errors
Here is the list of files with format issues in your PR:
|
The dev-bundle-plugin also needs to implement the new
Also it feels like the extensions should be an addition to the existing and not replacing the list of extensions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of comments:
- I agree with @caalador that the configurable extensions should be added to the default list and should not replace them.
- it would be better to define the default extensions in a single place instead of having duplication in Maven and Gradle plugin.
FrontendUtils
class could be a good host. - I know that in the Vite configuration file, the constant is named
projectFileExtensions
, but IMO it doesn't sound like a good name for a plugin setting. What aboutfrontendFileExtensions
? Could it be a better name?
flow-server/src/main/java/com/vaadin/flow/server/frontend/TaskUpdateVite.java
Outdated
Show resolved
Hide resolved
flow-server/src/main/java/com/vaadin/flow/server/frontend/TaskUpdateVite.java
Outdated
Show resolved
Hide resolved
I agree with everything and will make changes later. Thanks for considering this! |
… add to existing ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation seems broken because of a missing comma in placeholder replacement.
I also suggest adding a couple of tests in TaskUpdateViteTest
like the following one
@Test
public void generatedTemplate_extraFrontendExtension_addedToViteConfiguration()
throws IOException {
options.withExtraProjectFileExtensions(List.of(".svg", ".ico"));
TaskUpdateVite task = new TaskUpdateVite(options, null);
task.execute();
File configFile = new File(temporaryFolder.getRoot(),
FrontendUtils.VITE_GENERATED_CONFIG);
String template = IOUtils.toString(configFile.toURI(),
StandardCharsets.UTF_8);
Assert.assertTrue(
"Extra frontend extensions should be added to vite configuration, but was not.",
template.contains(
"const projectFileExtensions = ['.js', '.js.map', '.ts', '.ts.map', '.tsx', '.tsx.map', '.css', '.css.map', '.svg', '.ico'];"));
}
return "'" + StringEscapeUtils.escapeJava(ext) | ||
+ "'"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like to me that StringEscapeUtils.escapeJava
does not escape single quotes, that is the only replacement that we need (e.g. ext.replace("'", "\\'")
).
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
}).collect(Collectors.joining(", "))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The result of this string seems not correct; it will be appended to the existing list without a coma.
const projectFileExtensions = ['.js', '.js.map', '.ts', '.ts.map', '.tsx', '.tsx.map', '.css', '.css.map''.svg', '.ico'];
An option could be the following, for example
String extraExtension = "";
if (options.getExtraProjectFileExtensions() != null
&& !options.getExtraProjectFileExtensions().isEmpty()) {
extraExtension =
Optional.ofNullable(options.getExtraProjectFileExtensions())
.orElse(Collections.emptyList()).stream()
.map(ext -> ext.replace("'", "\\'"))
.collect(Collectors.joining("', '", ", '", "'"));
}
template = template.replace("#extraProjectFileExtensions#", extraExtension);
* Hashes are calculated for these files as part of detecting if a new prod | ||
* bundle should be generated. | ||
*/ | ||
public abstract val extraProjectFileExtensions: ListProperty<String> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still not convinced by the setting name. It still seems too generic to me.
I mean, the purpose is to add extension for frontend files that should be considered, not overall project files.
I propose something like frontendExtraFileExtensions
or frontendAdditionalFileExtensions
@mshabarov what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
frontendExtraFileExtensions
sounds like a good name, or frontendBuildExtraFileExtensions
may be even more descriptive for developer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additional note: it would probably make sense that configuration setting does not require the extension to start with a dot. I would prefer a configuration like
<extraProjectFileExtensions>
<extraProjectFileExtension>svg</extraProjectFileExtension>
<extraProjectFileExtension>ico</extraProjectFileExtension>
</extraProjectFileExtensions>
rather than
<extraProjectFileExtensions>
<extraProjectFileExtension>.svg</extraProjectFileExtension>
<extraProjectFileExtension>.ico</extraProjectFileExtension>
</extraProjectFileExtensions>
It would be better if the dot would be automatically added at runtime, if not already defined in configuration.
* Get the list of project file extensions. | ||
* | ||
* @return list of project file extensions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add a note on the expected extension format here (e.g. no initial dot) with a simple example list.
@@ -232,6 +233,9 @@ public abstract class FlowModeAbstractMojo extends AbstractMojo | |||
@Parameter(property = InitParameters.REACT_ENABLE, defaultValue = "${null}") | |||
private Boolean reactEnable; | |||
|
|||
@Parameter(defaultValue = "${null}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add a property
attribute named for example frontend.extraFileExtensions
so that it could be specified also on the command line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, the field needs Javadoc. IIRC they are used for maven goal documentation
* The list of extra file extensions that are considered project files. | ||
* Hashes are calculated for these files as part of detecting if a new prod | ||
* bundle should be generated. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add a note on expected extension format and a simple example list.
|
||
/** | ||
* Sets the extra project file extensions. | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to provide additional detail on the expected extension format and perhaps a simple example
@oliveryasuna let me know if you need help in setting up the tests or if you have any doubts |
@oliveryasuna are you still interested in/do you have time to complete this PR? |
Hey @mcollovati, sorry, it is completely fell off my radar. If the flow team could finish it off, that would be great! This will allow us and many to simplify our build process. |
Opened new PR with commits from this one. See #20397 |
@oliveryasuna thanks again for your contribution. It has been merged via other pull request, so I'm closing this one. |
This ticket/PR has been released with Vaadin 24.6.0.alpha4 and is also targeting the upcoming stable 24.6.0 version. |
Description
Please see the issue.
Fixes #19527
Type of change
Checklist
Additional for
Feature
type of change